﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ScrappyDB.Linq;

namespace ScrappyDB.IntegrationTests.AwsQuery101Examples
{
    [TestFixture]
    public class MultiplePredicateTests
    {
        /************************************************************************************
        * Example SQL:          select * from mydomain where Rating = '****'  	
        * Description:          Retrieves all items that have a "****" Rating. 	
        * Expected result:      0802131786, 1579124585 
        ************************************************************************************/
        [Test]
        public void AnyTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Rating.Any("****") select a;

            Assert.AreEqual(2, query.ToList().Count);
        }

        /************************************************************************************
        * Example SQL:          select * from mydomain where every(Rating) = '****'  	
        * Description:          Retrieves all items that only have a "****" Rating. Items are not returned that have a multi-valued Rating attribute that contains any value other than '****.' 	
        * Expected result:      0802131786 
        ************************************************************************************/
        [Test]
        public void EveryTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Rating.Every("****") select a;

            Assert.AreEqual(1, query.ToList().Count);
        }
        
        /************************************************************************************
        * Example SQL:          select * from mydomain where Keyword = 'Book' intersection Keyword = 'Hardcover'  	
        * Description:          Retrieves all items that have a "Book" Keyword and a "Hardcover" Keyword. 
        *                       The first predicate produces 0385333498, 0802131786, and 1579124585. The second produces 1579124585. 
        *                       The intersection operator returns results that appear in both queries. 	
        * Expected result:      1579124585 
        ************************************************************************************/
        [Test]
        public void IntersectionTest()
        {
            var dbContext = new AwsSampleContext();
            var query = from a in dbContext.Books where a.Keywords.Any("Book") && a.Keywords.Any("Hardcover") select a;

            Assert.AreEqual(1, query.ToList().Count);
        }

    }
}
